package kr.or.eclipse.democamp;

import javax.mail.Transport;
import javax.mail.internet.MimeMessage;

public class Mailer {
	private ConfirmMailTemplate confirmMailGenerator = new ConfirmMailTemplate();
	private MailMessageBuilder messageBuilder = new MailMessageBuilder();

	public Exception sendConfirmMail(Contact contact) {
		try {

			ActivateToken token = new ActivateToken();
			token.setMail(contact.getMail());

			PMF.get().getPersistenceManager().makePersistent(token);

			ActivationMailData data = new ActivationMailData(contact, token);

			String mail = this.confirmMailGenerator.generate(data);
			MimeMessage msg = messageBuilder.createMessage(contact.getMail(), "이클립스 10살 생일파티 참가 확인 메일", mail);
			Transport.send(msg);
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return e;
		}
	}

}